package de.carcophan.jimdb.ejb.entites;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.hibernate.validator.constraints.Email;


@Entity
@Table(name = "USERS", uniqueConstraints =
@UniqueConstraint(columnNames = {"LOGINID"}))
public class User implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @NotNull
    @Size(min = 1, max = 64)
    @Column(unique = true, nullable = false, length = 64)
    private String loginId;
    @NotNull
    @Size(min = 1, max = 64)
    @Column(nullable = false, length = 64)
    private String firstName;
    @NotNull
    @Size(min = 1, max = 128)
    @Column(nullable = false, length = 128)
    private String lastName;
    @NotNull
    @Size(max = 128)
    @Email
    @Column(nullable = false, length = 128)
    private String email;
    @Temporal(TemporalType.DATE)
    private Date joined;
    @NotNull
    @Size(min = 1, max = 128)
    @Column(nullable = false, length = 128)
    private String password;
    @Basic(optional = false)
    @Column(nullable = false)
    private Boolean locked;
    @OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
    private List<UserMovies> movies;
    @ManyToOne
    private Role userRole;

    public Role getUserRole() {
        return userRole;
    }

    public void setUserRole(Role userRole) {
        this.userRole = userRole;
    }
    @Transient
    private String passwordConfirm;

    public String getPasswordConfirm() {
        return passwordConfirm;
    }

    public void setPasswordConfirm(String passwordConfirm) {
        this.passwordConfirm = passwordConfirm;
    }

    public List<UserMovies> getMovies() {
        return movies;
    }

    public void setMovies(List<UserMovies> movies) {
        this.movies = movies;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public Date getJoined() {
        return joined;
    }

    public void setJoined(Date joined) {
        this.joined = joined;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public Boolean getLocked() {
        return locked;
    }

    public void setLocked(Boolean locked) {
        this.locked = locked;
    }

    public String getLoginId() {
        return loginId;
    }

    public void setLoginId(String loginId) {
        this.loginId = loginId;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public String toString() {
        return "User{" + "loginId=" + loginId + "email=" + email + '}';
    }
}
